#ifdef SU1
//#define _GLIBCXX_DEBUG
#endif

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forl(i, n) for (int i = 1; i <= int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i <= int(r); i++)
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define ft first
#define sc second
#define x first
#define y second

template<typename X> inline X abs(const X& a) { return a < 0 ? -a : a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld PI = acosl(ld(-1));
const ld EPS = 1e-9;

const int N = 100 * 1000 + 13;
const int K = 20;
const int M = K * N;

int n, m;
pt s[N];
vector<int> g[N];
int xs[M], szxs;
int p[M];

inline bool read()
{
	if (scanf("%d%d", &m, &n) != 2) return false;
	forn(i, n)
	{
		assert(scanf("%d%d", &s[i].ft, &s[i].sc) == 2);
		//s[i] = mp(0, m - 1);
		g[i].clear();
	}
	return true;
}

inline int myrand() { return rand() ^ (rand() << 15); }

inline int normal(int x)
{
	if (x < 0) x += m;
	if (x >= m) x -= m;
	return x;
}

void buildGraph()
{
	szxs = 0;
	forn(i, n)
	{
		int lf = s[i].ft, rg = s[i].sc;
		if (rg < lf) rg += m;
		
		if (rg - lf <= K)
		{
			forn(j, rg - lf + 1)
			{
				g[i].pb(normal(lf + j));
				xs[szxs++] = normal(lf + j);
			}
			continue;
		}
		
		forn(j, K / 4)
		{
			g[i].pb(lf);
			xs[szxs++] = lf;
			lf = normal(lf + 1);
			g[i].pb(rg);
			xs[szxs++] = rg;
			rg = normal(rg - 1);
		}
		
		forn(j, K / 2)
		{
			int x = normal(lf + myrand() % (rg - lf + 1));
			g[i].pb(x);
			xs[szxs++] = x;
		}
	}
	
	sort(xs, xs + szxs);
	szxs = int(unique(xs, xs + szxs) - xs);
	
	forn(i, n) forn(j, sz(g[i])) g[i][j] = int(lower_bound(xs, xs + szxs, g[i][j]) - xs);
	
	forn(i, szxs) p[i] = -1;
	
	//cerr << "=== build = " << clock() << " ===" << endl;
}

int used[N], u;
int was[N], w;

bool kuhn (int v)
{
	if (used[v] == u) return false;
	used[v] = u;
	
	forn(i, sz(g[v]))
	{
		int to = g[v][i];
		if (p[to] == -1)
		{
			p[to] = v;
			return true;
		}
	}
	
	forn(i, sz(g[v]))
	{
		int to = g[v][i];
		if (p[to] == -1 || kuhn(p[to]))
		{
			p[to] = v;
			return true;
		}
	}
		
	return false;
}

inline void solve()
{
	buildGraph();
	
	//forn(i, szxs) cerr << xs[i] << ' '; cerr << endl;
	//forn(i, n) { forn(j, sz(g[i])) cerr << g[i][j] << ' '; cerr << endl; }
	
	w++;
	forn(i, n)
	{
		forn(j, sz(g[i])) if (p[g[i][j]] == -1)
		{
			was[i] = w;
			p[g[i][j]] = i;
			break;
		}
	}
	
	forn(i, n)
	{
		if (was[i] == w) continue;
		
		u++;
    	if (!kuhn(i))
    	{
    		puts("NO");
    		return;
    	}
	}
	puts("YES");
}

int main()
{
#ifdef SU1
	assert(freopen("input.txt", "rt", stdin));
//	assert(freopen("output.txt", "wt", stdout));
#endif

	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(5);
	
	int testCount;
	cin >> testCount;
	
	forn(test, testCount)
	{
		assert(read());
		solve();
	}
	
#ifdef SU1
	cerr << "=== TIME : " << clock() << " ===" << endl;
#endif
	return 0;
}
